package com.gonsin.gview.logic.utils;

import org.apache.commons.beanutils.Converter;

import java.util.Map;

/**
 * list的处理
 */
public class CommonListClassConverter implements Converter {

    private Class clazz;

    public CommonListClassConverter(Class clazz) {
        this.clazz = clazz;
    }

    @Override
    public <T> T convert(Class<T> type, Object value) {
        if(value == null){
            return null;
        }
        if(clazz == value.getClass()){
            return (T) value;
        }
        if(value instanceof Map){
            try {
                return ValueUtils.mapToObject((Map<String, Object>) value, type);
            } catch (Exception ex) {
                return null;
            }
        }
        return null;

    }
}
